<template></template>
<script setup lang="ts">
	import {watch, ref, computed, createVNode} from 'vue'
	import {ExclamationCircleOutlined} from '@ant-design/icons-vue'
	import {Modal, message} from 'ant-design-vue'
	import {houseConfigMislaid} from '@/api/dictionary'

	const props = defineProps({
		visible: {
			type: Boolean,
			required: true
		},
		data: {
			type: Object,
			required: true
		}
	})
	const emit = defineEmits(['update:visible', 'success'])
	const cancel = () => {
		emit('update:visible', false)
	}
	watch(
		() => props.visible,
		(newVal: boolean) => {
			if (newVal) {
				Modal.confirm({
					title: '遗失',
					centered: true,
					icon: createVNode(ExclamationCircleOutlined),
					content: '确定将物品标记为遗失状态吗？',
					onOk() {
						return houseConfigMislaid({
							id: props.data.id
						})
							.then((res: any) => {
								message.success('操作成功')
								emit('success')
							})
							.finally(() => {
								cancel()
							})
					},
					onCancel() {
						cancel()
					}
				})
			}
		}
	)
</script>
